#region Usings

using System;
using log4net;
using Ninject.Core.Activation;
using Ninject.Core.Binding;

#endregion

namespace Karma.Framework.Core.IoC
{
    public class IoCUtils
    {
        private static ILog LOG = LogManager.GetLogger(typeof(IoCUtils).Name);

        public static Type GetImplementationType(Type interfaceType)
        {
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug(string.Format("Getting the implementation type for: {0}", interfaceType.Name));
            }
            var components = IoCFactory.Kernel.Components;
            // prepare
            var selector = components.Get<IBindingSelector>();
            var context = components.Get<IContextFactory>().Create(interfaceType);
            
            return selector.SelectBinding(interfaceType, context).Provider.GetImplementationType(context);
        }
    }
}